package cn.findviewbydream.controller;

import cn.findviewbydream.dto.Result;
import cn.findviewbydream.entity.UserEntity;
import cn.findviewbydream.service.LoginService;
import cn.findviewbydream.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**********************************
 * 工程：who
 * 作者：白雨濃 evil
 * 时间：2017/4/9 14:19
 * 邮箱：evilbai@foxmail.com
 * 内容：登录Controller
 **********************************/
@RestController
public class LoginController
{

    private final LoginService service;

    @Autowired
    public LoginController(LoginService service)
    {
        this.service = service;
    }

    /**
     * 获取用户实体
     *
     * @return Result<UserEntity>
     */
    @GetMapping("/user/{userId}")
    public Result getUser(@PathVariable String userId, HttpSession session) throws Exception
    {
        return ResultUtil.success(service.getUser(userId, session));
    }

    /**
     * 更新用户实体
     *
     * @return Result<UserEntity>
     */
    @PutMapping("/user")
    public Result<UserEntity> putUser()
    {
        return null;
    }

    /**
     * 注册
     *
     * @return Result<UserEntity>
     */
    @PostMapping("/user")
    public Result<UserEntity> register()
    {
        return null;
    }


    /**
     * 登录
     *
     * @return Result<UserEntity>
     */
    @PostMapping("/login")
    public Result login(String userId, String password)
    {
        return ResultUtil.success(service.login(userId, password));
    }
}
